<?php

namespace app\api\controller;

use app\admin\model\SourceConfig;
use app\admin\model\yexam\Ad;
use app\common\controller\Api;
use app\common\model\Config;
use think\response\Json;

/**
 * @ApiSector (首页接口)
 * @ApiInternal
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {
        $this->success('请求成功');
    }
	
	//跳转程序
	public function select(){
		$url  =  'http://vip.niukewang.com/h5/'; 
		$this->success('请求成功',$url);
	}
    //============ 关于我们  =======
    public function about() : Json
    {
        $config = new Config();
        $siteInfo = [];
        foreach ($config->where('group','sites')->select() as $k => $v) {
            $value = $v->toArray();
            $siteInfo[$value['name']] = $value['value'];
        }
        $config = $siteInfo;
        $this->success('ok',$config,200);
    }
    //======== 获取首页的数据
    public function renderHome()
    {
        $platformId = $this->request->param('id');
        $config = SourceConfig::get($platformId);
        if (is_null($config))
            $this->error('请求错误');
        $data = $config->extend;
        if (is_null($data))
            $this->error('没有配置首页数据请配置.');
        $data = json_decode($data,true);
        $swiper = new Ad();
        $tmp  = [];
        $imgs = $swiper->where('id','in',$data['swiper'])->select();
        foreach ($imgs as $Key => $va)
        {
            array_push($tmp,$this->request->domain().$va['image']);
        }
        $data['swiper'] = $tmp;
        foreach ($data['module'] as $kkk => $vvv)
        {
            $data['module'][$kkk]['icon'] = explode(',',$vvv['icon'])[0];
        }
        foreach ($data['nav'] as $jj => $ii)
        {
            $data['nav'][$jj]['icon'] = explode(',',$ii['icon']);
        }
        $data['login_entry'] = $config['login_entry'];
        $data['index_style'] = $config['index_style'];
        $data['appContent'] = $config['app_page_content'];//===== app下载页面的内容
        $data['page_name'] = $config['page_name'];
        $data['is_ios'] = $config['is_ios'];
        $data['source'] = $config;
        $this->success('ok',$data);
    }
}
